home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 22
/
Amiga Format AFCD22 (Jan 1998, Issue 106).iso
/
-in_the_mag-
/
converters
/
graphics
/
netpbm
/
pbmrexx
/
rexx
/
anytopnm.rexx
next >
Wrap
OS/2 REXX Batch file
|
1997-11-16
|
8KB
|
245 lines
/* anytopnm - attempt to convert an unknown type of image file to a P?M file.
*
* Copyright (C) 1994 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
* Based on anytopnm (sh-script) by Jef Poskanzer
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. This software is provided "as is" without express or
* implied warranty.
*
* $VER: anytopnm 1.4
*/
parse source junk junk progname junk
address command
signal on error
signal on break_c
signal on break_d
signal on ioerr
signal on halt
ID = pragma('Id')
if ~open(err, "CONSOLE:", 'W') then exit 20
if ~show('L', 'rexxsupport.library') then do
if ~addlib('rexxsupport.library', 0, -30, 0) then exit 20
end
if ~showlist('A', 'PBMTMP') then 'assign PBMTMP: T:'
tmpfiles = ''
i = 0
retval = 0
parse arg first tail
if abbrev(first, '-', 1) then call usage
if first = '' | tail ~= '' then call usage
orig = first
again = 1
do while again = 1
tmpfile = 'PBMTMP:atn.'i'.'ID
i = i+1
'file' first '>' tmpfile
if ~open(descfile, tmpfile, 'R') then do
call writeln err, 'file failed?? - aborting'
retval = 20
leave
end
desc = upper(readln(descfile))
call close descfile
call rm tmpfile
parse var desc junk desc /* skip filename */
again = 0
select
when pos('PBM', desc) > 0 | pos('PGM', desc) > 0 | pos('PPM', desc) > 0 then do
'pnmcat -tb' first
end
when pos('SUN', desc) > 0 | pos('RASTERFILE', desc) > 0 then do
'rasttopnm' first
end
when pos('GIF', desc) > 0 then do
'giftopnm' first
end
when pos('TIFF', desc) > 0 then do
'tifftopnm' first
end
when pos('IFF', desc) > 0 & pos('ILBM', desc) > 0 then do
'ilbmtoppm' first
end
when pos('IFF', desc) > 0 & pos('RGB8', desc) > 0 then do
'ilbmtoppm' first
end
when pos('IFF', desc) > 0 & pos('RGBN', desc) > 0 then do
'ilbmtoppm' first
end
when pos('IFF', desc) > 0 & pos('PBM ', desc) > 0 then do
'ilbmtoppm' first
end
when pos('LISP', desc) > 0 then do
'lispmtopgm' first
end
when pos('PC', desc) > 0 & pos('PAINTBRUSH', desc) > 0 then do
'pcxtoppm' first
end
when pos('BENNET', desc) > 0 then do
'ybmtopbm' first
end
when pos('SGI', desc) > 0 & pos('IMAGE', desc) > 0 then do
'sgitopnm' first
end
when pos('Utah', desc) > 0 & pos('RLE', desc) > 0 then do
'rletopnm' first
end
when pos('COMPRESS', desc) > 0 then do
'compress -d <' first '>' tmpfile
first = tmpfile
tmpfiles = tmpfiles tmpfile
again = 1
end
when pos('BTOA', desc) > 0 then do
'atob <' first '>' tmpfile
first = tmpfile
tmpfiles = tmpfiles tmpfile
again = 1
end
otherwise do
/* Can't figure out the file type from the magic number,
try the extension. */
desc = upper(orig)
select
when exten(desc, 'PBM') | exten(desc, 'PGM') | exten(desc, 'PPM') then do
'pnmcat -tb' first
end
when exten(desc, 'X') | exten(desc, 'XBM') | exten(desc, 'X10BM') | exten(desc, 'X11BM') | exten(desc, 'BITMAP') then do
'xbmtopbm' first
end
when exten(desc, 'R') | exten(desc, 'RAST') then do
'rasttopnm' first
end
when exten(desc, 'MAC') | exten(desc, 'MACP') then do
'macptopbm' first
end
when exten(desc, 'G3') | exten(desc, 'FAX') then do
'g3topbm' first
end
when exten(desc, 'XWD') | exten(desc, 'X10WD') | exten(desc, 'X11WD') then do
'xwdtopnm' first
end
when exten(desc, 'BRUSH') then do
'brushtopbm' first
end
when exten(desc, 'IMG') then do
'gemtopbm' first
end
when exten(desc, 'PCX') then do
'pcxtoppm' first
end
when exten(desc, 'PIC') | exten(desc, 'PICT') | exten(desc, 'PICT2') then do
'picttoppm' first
end
when exten(desc, 'TIF') | exten(desc, 'TIFF') then do
'tifftopnm' first
end
when exten(desc, 'FS') | exten(desc, 'FACE') then do
'fstopgm' first
end
when exten(desc, 'HIPS') then do
'hipstopgm' first
end
when exten(desc, 'FITS') then do
'fitstopnm' first
end
when exten(desc, 'GIF') then do
'giftopnm' first
end
when exten(desc, 'IFF') | exten(desc, 'ILBM') | exten(desc, 'HAM') | exten(desc, 'HAM8') then do
'ilbmtoppm' first
end
when exten(desc, 'LISPM') then do
'lispmtopgm' first
end
when exten(desc, 'MTV') then do
'mtvtoppm' first
end
when exten(desc, 'QRT') | exten(desc, 'DIS') | exten(desc, 'DUMP') then do /* POVRay */
'qrttoppm' first
end
when exten(desc, 'TGA') | exten(desc, 'TARGA') then do
'tgatoppm' first
end
when exten(desc, 'XIM') then do
'ximtoppm' first
end
when exten(desc, 'XPM') | exten(desc, 'XPM2') then do
'xpmtoppm' first
end
when exten(desc, 'PI1') then do
'pi1toppm' first
end
when exten(desc, 'PI3') then do
'pi3topbm' first
end
when exten(desc, 'SPU') then do
'sputoppm' first
end
when exten(desc, 'SPC') then do
'spctoppm' first
end
when exten(desc, 'YBM') | exten(desc, 'FACE') then do
'ybmtopbm' first
end
when exten(desc, 'SGI') then do /* also .RGB and .BW */
'sgitopnm' first
end
when exten(desc, 'RLE') then do
'rletopnm' first
end
otherwise do
call writeln(err, orig ': unknown file type')
retval = 5
end
end /* select */
end /* otherwise */
end /* select */
end /* do */
if tmpfiles ~= '' then do
call rm tmpfiles
end
exit retval
usage:
call writeln err, 'usage:' progname '<file>'
exit 10
rm: procedure
arg name
signal off error /* ignore WARN */
'delete' name 'quiet force >NIL:'
signal on error
return
error:
ioerr:
halt:
call writeln err, progname ': error at line' SIGL 'code' RC
break_c:
break_d:
if tmpfiles ~= '' then do
call rm tmpfiles
end
exit 20
exten: procedure
arg name, ext
ext2 = '.'ext
ext3 = '.'ext'.'
return (pos(ext3, name) > 0 | right(name, length(ext2)) = ext2)